package com.rybbaby.tss.tasks.core.task.dao.imp;

import com.rybbaby.tss.tasks.core.task.dao.ITssMemberCheckAttendanceDao;
import com.rybbaby.tss.tasks.core.task.entity.TssMemberCheckAttendance;
import com.rybbaby.tss.tasks.core.web.dao.imp.GenericDao;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

/**
 * @description 会员考勤记录表数据库操作实现
 * 
 * @author 雷春琼
 * 
 * @createDate 2017-08-10 上午10:33:46w zai
 */
@Repository
public class TssMemberCheckAttendanceDaoImp extends GenericDao<TssMemberCheckAttendance> implements ITssMemberCheckAttendanceDao {

    @Override
    public List<Map<String, Object>> findAttendanceList(int attendenceStatus,int type) throws Exception {
        String sql="SELECT\n" +
                "\tp.memberId,\n" +
                "\tp.id as memberPackageId,\n" +
                "\tc.id as classId,\n" +
                "\tc.expendClassHour\n" +
                "FROM\n" +
                "\ttss_member_attend_class_record r\n" +
                "LEFT JOIN tss_classes c \n" +
                "ON r.classId = c.id\n" +
                "LEFT JOIN tss_member_package p\n" +
                "ON r.memberPackageId = p.id\n" +
                "LEFT JOIN tss_member_check_attendance a\n" +
                "ON a.classId = r.classId\n" +
                "WHERE\n" +
                "\tc.type = ?\n" +
                "AND to_days(now()) - to_days(a.createTime) <= 1 \n" +
                "AND a.attendenceStatus = ?\n" +
                "AND p.memberId = a.memberId\n" +
                "GROUP BY a.id\n";
        return this.findForJdbc(sql,new Object[]{type,attendenceStatus});
    }
}
